﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Playables;

public class Example3 : MonoBehaviour
{
    public Animator animator;
    public AnimationClip animationClip;
    public float amp = 1f;
    public float freq = 1f;
    public float duration = 1f;
    PlayableGraph mPlayableGraph;


    IEnumerator Start()
    {
        mPlayableGraph = PlayableGraph.Create();

        var clipPlayable = AnimationClipPlayable.Create(mPlayableGraph, animationClip);

        var scriptPlayable = ScriptPlayable<SinWigglePlayableBehaviour>.Create(mPlayableGraph);
        scriptPlayable.GetBehaviour().Init(transform, amp, freq, duration);
        scriptPlayable.SetInputCount(1);

        var output = AnimationPlayableOutput.Create(mPlayableGraph, "SinWiggle", animator);
        output.SetSourcePlayable(scriptPlayable);

        mPlayableGraph.Play();

        yield return new WaitForSeconds(2f);

        mPlayableGraph.Stop();
    }

    void OnDestroy()
    {
        mPlayableGraph.Destroy();
    }
}
